package ru.papergames.web.blines.battle;

import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.InitializingBean;
import ru.common.hibernate.HibernateActionExecutor;
import ru.papergames.web.cache.CacheManager;

/**
 * TODO: add description
 * Date: 21.12.11 23:27
 *
 * @author Alexander Troshanin
 */
public class BattleFactoryBean implements FactoryBean, InitializingBean, DisposableBean {

    private HibernateActionExecutor hiber;

    public void setHiber(HibernateActionExecutor hiber) {
        this.hiber = hiber;
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        BattleServersManager.createInstance(hiber);
        BattleServersManager.getInstance().start();
    }

    @Override
    public Object getObject() throws Exception {
        return BattleServersManager.getInstance();
    }

    @Override
    public Class getObjectType() {
        return BattleServersManager.class;
    }

    @Override
    public boolean isSingleton() {
        return true;
    }

    @Override
    public void destroy() throws Exception {
        BattleServersManager.getInstance().shutdown();
    }
}
